using System;
using System.Collections.Generic;
using Tarkin.InfrastructureLibrary.Utilities.Collections;

namespace Tarkin.InfrastructureLibrary.Core.Basic
{
    /// <summary>
    /// The Class class is the implementation of the Class metaclass as defined by 
    /// section 10.2.1 of the Unified Modeling Language: Infrastructure specfication 
    /// (version 2.1.1, dated 07-02-06).
    /// </summary>
    /// <remarks>Tarkin classes are NOT thread-safe.</remarks>
    public class Class : Type
    {

#region Private Members

        /// <summary>
        /// Whether the Class is abstract.
        /// </summary>
        private bool isAbstract = false;

        /// <summary>
        /// The immediate superclass(es) of the Class.
        /// </summary>
        private Set < Class > superClasses = null;

        /// <summary>
        /// The attributes owned by a Class. These do not include the inherited attributes.
        /// </summary>
        private List < Property > ownedAttributes = null;

        /// <summary>
        /// The Operations owned by a Class. These do not include the inherited operations.
        /// </summary>
        private List < Operation > ownedOperations = null;

#endregion


#region Constructors

        /// <summary>
        /// Overloaded constructor.
        /// </summary>
        /// <param name="name">The name of the Class.</param>
        public Class ( string name ) : base ( name )
        { }

        /// <summary>
        /// Overloaded constructor.
        /// </summary>
        /// <param name="isAbstract">Whether the Class is abstract.</param>
        /// <param name="name">The name of the Class.</param>
        public Class ( bool isAbstract, 
                       string name ) : base ( name )
        {
            IsAbstract = isAbstract;
        }

#endregion


#region Public Properties

        /// <summary>
        /// Whether the Class is abstract.
        /// </summary>
        public bool IsAbstract
        {
            get
            {
                return isAbstract;
            }

            set
            {
                isAbstract = value;
            }
        }

        /// <summary>
        /// The immediate superclass(es) of the Class.
        /// </summary>
        public Set < Class > SuperClasses
        {
            get
            {
                if ( superClasses == null )
                {
                    superClasses = new Set < Class > ();
                }

                return superClasses;
            }
        }

        /// <summary>
        /// The attributes owned by a Class. These do not include the inherited attributes.
        /// </summary>
        public IList < Property > OwnedAttributes
        {
            get
            {
                if ( ownedAttributes == null )
                {
                    ownedAttributes = new List < Property > ();
                }

                return ownedAttributes;
            }
        }

        /// <summary>
        /// The Operations owned by a Class. These do not include the inherited operations.
        /// </summary>
        public IList < Operation > OwnedOperations
        {
            get
            {
                if ( ownedOperations == null )
                {
                    ownedOperations = new List < Operation > ();
                }

                return ownedOperations;
            }
        }

#endregion

    }
}
